package com.ruoyi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.CustomerAddress;
import com.ruoyi.service.ICustomerAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/webshop/customerAddress")
public class CustomerAddressController extends BaseController {
    @Autowired
    private ICustomerAddressService customerAddressService;

    // 全查
    @GetMapping("/list")
    public List<CustomerAddress> list(){
        List<CustomerAddress> list = customerAddressService.list();
        return list;
    }
    @GetMapping("/listForPage")
    public TableDataInfo listForPage(CustomerAddress customerAddress) {
        System.out.println("customerAddress = " + customerAddress);
        startPage();
        List<CustomerAddress> list = customerAddressService.listForPage(customerAddress);


        return getDataTable(list);
    }
    // 根据id查一条
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id){
        System.out.println("id = " + id);
        CustomerAddress customerAddress = customerAddressService.getById(id);
        return success(customerAddress);
    }
    // 添加
    @PostMapping()
    public AjaxResult add(@RequestBody CustomerAddress customerAddress){
        System.out.println("customerAddress = " + customerAddress);
        int add = customerAddressService.save(customerAddress);
        return toAjax(add);
    }
    // 修改
    @PutMapping()
    public AjaxResult edit(@RequestBody CustomerAddress customerAddress){
        System.out.println("customerAddress = " + customerAddress);
        int edit = customerAddressService.updateById(customerAddress);
        return toAjax(edit);
    }
    // 根据ids删除多条
    @DeleteMapping("/{ids}")
    public AjaxResult deleteMany(@PathVariable Long[] ids){
        System.out.println("ids = " + Arrays.toString(ids));
        int delete = customerAddressService.removeByIds(ids);
        return toAjax(delete);
    }
}
